package utils;

import dao.UserDao;
import pojo.user.UserEntity;

import java.io.IOException;

/**
 * @author Limohan
 */
public class JudgeUtil {
    private final UserEntity userEntity;

    public JudgeUtil(UserEntity userEntity) {
        this.userEntity = userEntity;
    }

    public String judgeInput() throws IOException {
        UserDao userDao = new UserDao();
        if(userEntity.getAccount().equals("")) {
            return "账号不能为空";
        }
        if(userEntity.getPassword().equals("")){
            return "密码不能为空";
        }
        if(!(userEntity.getPassword().length()>=3&&userEntity.getPassword().length()<=12)){
            return "密码必须在3到12位之间";
        }
        if(!(userEntity.getPassword().matches("^[A-Za-z0-9]+$"))){
            return "密码必须由a-z  A-Z  0-9组成";
        }
        if(userEntity.getName().equals("")) {
            return "姓名不能为空";
        }
        if(userEntity.getPhone().length()!=11){
            return "电话必须在11位";
        }
        if(userEntity.getPower()==null){
            return "用户类型不能为空";
        }
        if(userDao.isUser(userEntity.getAccount())){
            return "该账号已被注册";
        }



        if((userEntity.getPhone().matches("^\\d{10}$"))){
            return "联系方式必须为11位的数字";
        }

        return null;
    }
}
